<%@page contentType="text/html" language="java" import="com.compuvest.web.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<%@ taglib uri="/WEB-INF/tld/head.tld" prefix="head" %>
<%@ taglib uri="/WEB-INF/tld/bottom.tld" prefix="bottom" %>
<%@ taglib uri="/WEB-INF/tld/leftmenu.tld" prefix="lmenu" %>
<%@ taglib uri="/WEB-INF/tld/items.tld" prefix="itemstld" %>
<%@ taglib uri="/WEB-INF/tld/navigation.tld" prefix="navigation" %>
<%@ taglib uri="/WEB-INF/tld/advertblock.tld" prefix="advert" %>

<jsp:useBean id="sb" class="MySQL" scope="application"/>
<jsp:useBean id="advertArray" class="AdvertArray" scope="application"/>
<jsp:useBean id="basket" class="Basket" scope="session"/>
<%!
    public static final int PREF_SIZE = 7;
%>
<%
    String thisURL = "ItemsAll.jsp";
    String pageName = "All Items";

    int pageNo = advertArray.getInt(request.getParameter("pg"), 0);
    int catID = advertArray.getInt(request.getParameter("cid"), 0);
    int scatID = advertArray.getInt(request.getParameter("sid"), 0);
    int sortID = advertArray.getInt(request.getParameter("srt"), 1);

    int advcatID = advertArray.getInt(request.getParameter("adcid"), advertArray.getAdvertRandomCategory());

    int lowPrice = advertArray.getFloatToInt(request.getParameter("lop"), 0);
    int hiPrice  = advertArray.getFloatToInt(request.getParameter("hip"), 0);

    // preference
    StringBuilder popUrl = new StringBuilder(200);
    StringBuilder hidden = new StringBuilder(200); // for price range
    java.util.Map<Integer,String> popData = null;
    if(scatID != 0) {
	popData = new java.util.HashMap(PREF_SIZE);
	for(int position = 0; position < PREF_SIZE; position++) {

	    String pop = advertArray.getString(request.getParameter("p" + position), "");
	    if(pop.length() == 0) continue;

	    popData.put(position, pop);
            hidden.append("<input type=hidden name=p").append(position).append(" value=").append(pop).append(" />");
	    popUrl.append("&p").append(position).append("=").append(java.net.URLEncoder.encode(pop,"UTF-8"));
	}
    }

    Items items = sb.getItemsAll(catID, scatID, sortID, popData, lowPrice, hiPrice, pageNo);

    session.setAttribute("thisURL", thisURL);
    session.setAttribute("pageName", pageName);
%>
<html>
<%@include file="/incl/head.html" %>

<body onload='<%= (catID == 0) ? "menu();" : "" %>'>

<table style='height:100%;'>

<tr valign=top height=84>
 <td colspan=3>

<head:show
 pageName='<%= pageName %>' />

 </td>
</tr>

<tr valign=top>
 <td style="width:200px;">

<%
    if(catID == 0) {
%>
<%= advertArray.getMainMenu(request.isRequestedSessionIdFromCookie(), session) %>
<%
    }
    else{
%>
<form name=Preference action='<%= thisURL %>' method=POST>
<input type=hidden name=pg value=<%= pageNo %> />
<input type=hidden name=cid value=<%= catID %> />
<input type=hidden name=sid value=<%= scatID %> />
<input type=hidden name=srt value=<%= sortID %> />
<%= hidden.toString() %>

<lmenu:show
 pageName='<%= pageName %>'
 categoryID='<%= catID %>'
 subcategoryID='<%= scatID %>'
 lowPrice='<%= lowPrice %>'
 hiPrice='<%= hiPrice %>'
 pageUrl='<%= new StringBuilder(100).append(thisURL).append("?pg=0&srt=").append(sortID).toString() %>'
 items='<%= items %>'
 popUrl='<%= popUrl.toString() %>'
 popData='<%= popData %>'
/>

</form>
<%
    }
%>

 </td>

 <td align=center>
   <%-- begin Items content --%>

<navigation:show
 categoryID='<%= catID %>'
 subcategoryID='<%= scatID %>'
 lowPrice='<%= lowPrice %>'
 hiPrice='<%= hiPrice %>'
 items='<%= items %>'
 popUrl='<%= popUrl.toString() %>'
 popData='<%= popData %>'
 />

<%
    if(catID == 0) {
%>
<%--
<table id=cv_ahead border=1>
<tr align=center>
 <td><a href='<%= thisURL %>?adcid=573'><img src='../images/notebook.png' /><div>Notebook,<br/>PDA</div></a></td>
 <td><a href='<%= thisURL %>?adcid=446'><img src='../images/system.png' /><div>Systems,<br/>Barebones</div></a></td>
 <td><a href='<%= thisURL %>?adcid=9'><img src='../images/hardd.png' /><div>Storage<br/>Devices, HDD</div></a></td>
 <td><a href='<%= thisURL %>?adcid=30'><img src='../images/monitor.png' /><div>Monitors,<br/>TVs</div></a></td>
 <td><a href='<%= thisURL %>?adcid=304'><img src='../images/vicard.png' /><div>Video Cards</div></a></td>
 <td><a href='<%= thisURL %>?adcid=13'><img src='../images/printer.png' /><div>Printers</div></a></td>
 <td><a href='<%= thisURL %>?adcid=397'><img src='../images/keyboard.png' /><div>Input<br/>Devices</div></a></td>
</tr>
</table>
--%>

<advert:show
 advertItems='<%= advertArray.getAdvertItemsFirstPage(advcatID) %>'
/>

<%
    } // if(catID == 0)

    if(catID != 0 && scatID == 0) {
%>
<advert:show
 advertItems='<%= advertArray.getAdvertItemsCategoryPage(catID) %>'
/>
<%
    } // if(catID != 0 && scatID == 0)

    if(catID != 0 && scatID != 0) {
%>
<advert:show
 advertItems='<%= advertArray.getAdvertItemsPage(scatID) %>'
/>

<form name=SortForm action='<%= thisURL %>' method=POST>
<input type=hidden name=pg value=0 />
<input type=hidden name=cid value=<%= catID %> />
<input type=hidden name=sid value=<%= scatID %> />
<input type=hidden name=lop value=<%= lowPrice %> />
<input type=hidden name=hip value=<%= hiPrice %> />
<%= hidden.toString() %>

<itemstld:show
 categoryID='<%= catID %>'
 subcategoryID='<%= scatID %>'
 pageNo='<%= pageNo %>'
 pageUrl='<%= new StringBuilder(100).append(thisURL).append("?cid=").append(catID).append("&sid=").append(scatID).append("&lop=").append(lowPrice).append("&hip=").append(hiPrice).append(popUrl).toString() %>'
 reseller='<%= basket.getReseller() %>'
 items='<%= items %>'
 sortID='<%= sortID %>'
/>
</form>
<%
    } // if(catID != 0 && scatID != 0)
%>

  <%-- end Items content --%>
 </td>

 <td style="width:120px;">

<div style='background-color:white;text-align:center;font:bold 10px arial;color:#870101;'>
<div onclick="location.href='<%= application.getInitParameter("AdvertServer") %>excel/Wholesale Prices.xls'">
<fieldset style='cursor:pointer;'>
<img src='<%= application.getInitParameter("AdvertServer") %>excel/icon.png' style='float:left;'/>Wholesale Inventory<br/>Download Now
</fieldset>
</div>
</div>

 </td>
</tr>

<tr height=35>
 <td colspan=3>

<bottom:show />

 </td>
</tr>

</table>

</body>
<%@ include file="./incl/tracking.incl" %>
</html>
